<template>
  <a-card :bordered="false">
    <!-- 抽屉 -->
    <a-drawer title="分配工单" :width="screenWidth" @close="onClose" :visible="visible">
      <!-- 抽屉内容的border -->
      <div
        :style="{
          padding: '10px',
          border: '1px solid #e9e9e9',
          background: '#fff',
        }"
      >
        <div>
          <a-table
            ref="table"
            rowKey="id"
            size="middle"
            :columns="columns"
            :dataSource="dataSource"
            :pagination="ipagination"
            :loading="loading"
            @change="handleTableChange"
            :rowClassName="getRowClassname"
          >
            <span slot="action" slot-scope="text, record">
              <a @click="handleEdit(record)">更改为负责人</a>
              <a-divider type="vertical" />
              <a @click="handleReplace(record)">取消分配</a>
            </span>
          </a-table>
        </div>
      </div>
    </a-drawer>
    <!-- 字典数据 -->
  </a-card>
</template>

<script>
import pick from 'lodash.pick'
import { filterObj } from '@/utils/util'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
// import { recordFilterelement, findById } from '@/api/api'

export default {
  name: 'WorkServiceItemList',
  mixins: [JeecgListMixin],
  data() {
    return {
      columns: [
        {
          title: '姓名',
          align: 'center',
          dataIndex: 'name',
        },
        {
          title: '手机号',
          align: 'center',
          dataIndex: 'telephone',
        },
        {
          title: '是否为负责人',
          align: 'center',
          dataIndex: 'replacementdays',
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          scopedSlots: { customRender: 'action' },
        },
      ],
      queryParam: {
        id: '',
      },
      title: '操作',
      visible: false,
      screenWidth: 800,
      //设备详情
      model: {},
      //设备id
      id: '',
      status: 1,
      labelCol: {
        xs: { span: 5 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 12 },
        sm: { span: 12 },
      },
      url: {
        list: '/personnel/workPersonnel/list',
      },
    }
  },
  created() {
    // 当页面初始化时,根据屏幕大小来给抽屉设置宽度
    this.resetScreenSize()
  },
  methods: {
    edit(record) {
      //设备编号
      this.id = record.id
      this.queryParam = {}
      this.model = Object.assign({}, record)
      this.visible = true
      // 当其它模块调用该模块时,调用此方法加载字典数据
      this.loadData()
    },

    getQueryParams() {
      //update--begin--autor:wangshuai-----date:20191204------for：清空总条数 teambition JT-113------
      this.ipagination.total = 0
      //update--end--autor:wangshuai-----date:20191204------for：清空总条数 teambition JT-113------
      var param = Object.assign({}, this.queryParam)
      param.id = this.id
      param.field = this.getQueryField()
      param.pageNo = this.ipagination.current
      param.pageSize = this.ipagination.pageSize
      if (this.superQueryParams) {
        param['superQueryParams'] = encodeURI(this.superQueryParams)
        param['superQueryMatchType'] = this.superQueryMatchType
      }
      return filterObj(param)
    },

    // 添加字典数据
    handleAdd() {
      this.$refs.modalForm.add(this.dictId)
      this.$refs.modalForm.title = '新增'
    },
    showDrawer() {
      this.visible = true
    },
    onClose() {
      this.visible = false
      // this.dataSource = []
    },
    // 抽屉的宽度随着屏幕大小来改变
    resetScreenSize() {
      let screenWidth = document.body.clientWidth
      if (screenWidth < 600) {
        this.screenWidth = screenWidth
      } else {
        this.screenWidth = 700
      }
    },
    //update--begin--autor:wangshuai-----date:20191204------for：系统管理 数据字典禁用和正常区别开，添加背景颜色 teambition JT-22------
    //增加样式方法返回值
    getRowClassname(record) {
      if (record.status == 0) {
        return 'data-rule-invalid'
      }
    },
    //取消分配
    handleReplace(record) {
      var that = this
      //封装参数
      var param = {}
      param.recordld = record.recordId
      param.id = this.id
      recordFilterelement(param).then((res) => {
        if (res.success) {
          // 当其它模块调用该模块时,调用此方法加载字典数据 获取查询对象that.queryParam或是that.getQueryParams()
          //调用这个时候我们直接调用这个我们首先会调用本身的默认查询方法同时会调用与这个有关的也会查询
          //会加载当前的一个查询方法,ok的时候就会刷新ok的页面
          that.loadData()
          that.finByIdd()
          that.$emit('ok')
        }
      })
    },
    //查询设备详情
    finByIdd() {
      var that = this
      var param = {}
      param.id = this.id
      findById(param).then((res) => {
        if (res.success) {
          that.model = res.result.records[0]
        }
      })
    },
    //update--end--autor:wangshuai-----date:20191204------for：系统管理 数据字典禁用和正常区别开，添加背景颜色 teambition JT-22------
  },
}
</script>
<style lang="less" scoped>
//update--begin--autor:wangshuai-----date:20191204------for：系统管理 数据字典禁用和正常区别开，添加背景颜色 teambition JT-22------
/deep/ .data-rule-invalid {
  background: #f4f4f4;
  color: #bababa;
}
//update--begin--autor:wangshuai-----date:20191204------for：系统管理 数据字典禁用和正常区别开，添加背景颜色 teambition JT-22------
</style>